package com.zsk.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TestThread implements Runnable {

	private static int count = 0;
	private Lock lock = new ReentrantLock();

	@Override
	public void run() {
		test();
	}

	public void test() {
		lock.lock();
		try {
			for (int i = 0; i < 10; i++) {
				System.out.println(Thread.currentThread().getName() + ":" + count++);
			}

		} finally {
			lock.unlock();
		}

	}

	public static void main(String[] args) {

//		TestThread t1 = new TestThread();
//		TestThread t2 = new TestThread();
//		new Thread(t1).start();
//		new Thread(t1).start();

		ExecutorService musicPool = Executors.newSingleThreadExecutor();

		Runnable r = () -> System.err.println(System.currentTimeMillis());
		for (int i = 0; i < 20; i++) {
			musicPool.execute(r);
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}

}
